Writing Templates for Constructor 99
Copyright © Mark Carrington 1999
www.mutantpenguin.net
Introduction
Templates are HTML files with a number of proprietry command codes in them. When the file is opened, Constructor scans for these codes and acts accordingly to prompt the user for some soft of information to replace the command with.
Command Codes
Below is a list of all the command codes supported by Constructor, and a brief description of each one.
- {#prompt:variable-name} - Pops up a box containing a single line text box asking for text to be assigned to variable-name
- {#promptmulti:variable-name} - As above but with a multi-line text box. Constructor automatically places <br> tags at the end of each line.
- {#formatting:variable-name} - Displays the Font Wizard from which the user can select font formatting effects for the subsequent text. Note that this does not insert the closing tags.
- {#createtag:tag-name} - Displays the wizard for the tag named in the tag-name parameter. Valid values for this parameter are: anchor, font form, frame, images, jump, link, list, marquee, meta, redirect, style, stylesheet, symbol, table, video.
- {#loop:variable-name/n} ... {#endloop:variable-name} - Repeats the code between the two matching tags n times. n must be a valid integer number, or "prompt". If it is "prompt", then each time the {#loop} command is read the user is asked if they want to repeat the loop again.
- {#plugin:filename} - Runs the plugin with the specified file name. The path to the file is not required as all the plugin files have to be in the Addin folder in the Constructor folder.
- {#define:type/variable-name/value} - Sets variable-name to value, where variable-name is of type. type is one of: prompt, promptmulti, formatting. All further instances of variable-name are replaced with value automatically without prompting, provided that further instances are of type.
Reusing variable names
Once the user has been asked once for the value of a variable, if that variable name is used again then that instance is also replaced automatically with the same value. All instances of that variable name must be used in the same command, or an error message is shown. All commands and parameters are case-sensitive. It can be useful to use the same variable name, for instance in creating a link to an e-mail address where you want to show the address as the link. In that case, the following code could be used:
<a href="mailto:{#prompt:e-mail address}">{#prompt:e-mail address}</a>
In this example, Constructor finds the first instance of {#prompt:e-mail address} and shows a message box asking for the value of e-mail address. This value is then put into the <a href="mailto:"> tag, so forming a link to the address. Constructor then finds the second instance of {#prompt:e-mail address}, recognises that the user has already put in a value for e-mail address and so automatically places that value between the <a> and </a> tags, forming the text which the user will click on.
Loops
Loops can be used when a certain piece of code needs to be repeated a certain number of times, for example creating a list of links. To create a loop, simply type in the text you want for one item and then place the {#loop:name/number} command before it and the {#endloop:name} command after it. Any variables which are defined a value in the loop loose the value on each iteration of the loop. The following code can be used to create a list of five links:
<ul>
{#loop:links/5}
<li><a href="{#prompt:Target}">Link to {#prompt:Target}
{#endloop:links}
</ul>
In this example, firs the <ul> tag is put in to start a bulleted list. The line "<li><a href="{#prompt:Target}">Link to {#prompt:Target}" is then looped through five times. Although normally, as Target would have been assigned a value on a previous iteration, this is not the case as it looses it's value when Constructor reads the {#endloop:links} command. This means that the user has to enter a value on each iteration, but once the user has entered a value for the first instance of the command on each iteration, it is still stored for the next such command on that same iteration.
You can nest loops, i.e. have one loop inside another. Please note that loops cannot "overlap", e.g.
{#loop:loop1/2}
Place some text here
{#loop:loop2/2}
Some text here too
{#endloop:loop1} <-- Error here: loop1 closes before loop2 when loop2 started within loop1
{#endloop:loop2}
This code should look like:
{#loop:loop1/2}
Place some text here
{#loop:loop2/2}
Some text here too
{#endloop:loop2}
{#endloop:loop1}
Constructor's behaviour on encountering loops which overlap is undefined.
Note
You are limited to a maximum of 100 variable names. If you go past this limit, then variables which were assigned a value earliest will start to get overwritten. You will still be able to use these variable names, but Constructor will not save their value. Similarly, you cannot nest loops more than 100 in depth.